﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy2_9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            txtOutput.ReadOnly = true;
        }

        // ROT13 加密/解密方法
        private string Rot13(string input)
        {
            char[] chars = input.ToCharArray();
            for (int i = 0; i < chars.Length; i++)
            {
                char c = chars[i];
                if (Char.IsLetter(c))
                {
                    int offset = Char.IsUpper(c) ? 'A' : 'a';
                    chars[i] = (char)((c - offset + 13) % 26 + offset);
                }
            }
            return new string(chars);
        }

        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            string input = txtInput.Text;
            txtOutput.Text = Rot13(input);
        }

        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            // 因为 ROT13 是对等加密，解密就是再加密一次
            string input = txtInput.Text;
            txtOutput.Text = Rot13(input);
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            txtInput.Text = "";
            txtOutput.Text = "";
        }
    }
}
